define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'reservations/index' + location.search,
                    add_url: 'reservations/add',
                    edit_url: 'reservations/edit',
                    del_url: 'reservations/del',
                    multi_url: 'reservations/multi',
                    import_url: 'reservations/import',
                    table: 'reservations',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'room_id', title: __('Room_id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'store_id', title: __('Store_id')},
                        {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'number_of_people', title: __('Number_of_people')},
                        {field: 'number_of_men', title: __('Number_of_men')},
                        {field: 'number_of_women', title: __('Number_of_women')},
                        {field: 'deposit', title: __('Deposit'), operate:'BETWEEN'},
                        {field: 'deposit_status', title: __('Deposit_status')},
                        {field: 'reservation_status', title: __('Reservation_status')},
                        {field: 'penalty_fee', title: __('Penalty_fee'), operate:'BETWEEN'},
                        {field: 'rooms.id', title: __('Rooms.id')},
                        {field: 'rooms.room_number', title: __('Rooms.room_number'), operate: 'LIKE'},
                        {field: 'rooms.shop_id', title: __('Rooms.shop_id')},
                        {field: 'rooms.capacity', title: __('Rooms.capacity')},
                        {field: 'rooms.room_type', title: __('Rooms.room_type')},
                        {field: 'rooms.status', title: __('Rooms.status')},
                        {field: 'rooms.shared_table', title: __('Rooms.shared_table')},
                        {field: 'rooms.deposit', title: __('Rooms.deposit'), operate:'BETWEEN'},
                        {field: 'rooms.createtime', title: __('Rooms.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'rooms.updatetime', title: __('Rooms.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'rooms.deletetime', title: __('Rooms.deletetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'rooms.weigh', title: __('Rooms.weigh')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
